/**
* Created with Vim7.3 ubuntu12.04
* @fileOverview : 
* @author : Lyle <lylechen2014@gmial.com>
* @since : 2014-09-17 09:50:18
* @filename : static/logic/nmm/src/views/feedback.js
* @version : 
* @description : 
*/

define(function(require, exports, module){
    var feedbackView, userInfo,
        mId = 'feedback',reRender = false,menuName = 'feedback',
        panel = require('{component}panel/zepto.panel'),
        imglazyload = require('{component}imglazyload/zepto.imglazyload'),
        tpl = require('{view}feedback.tpl'),
        tplN = require('{view}userNav.tpl');

    feedbackView = Backbone.View.extend({

        el: '',

        template: _.template(tpl),
        templateN: _.template(tplN),

        initialize: function () {},

        render: function (obj) {
            if (!share.checkPermission(true)){return;};  
            share.reRender(reRender,mId);
            if ($('#'+mId).length < 1) { 
                $('body').append(this.template(lang));
                this.bindEvt();
                userInfo = share.userInfo();
            } else {
                $('#'+mId).css('display','block');
            }

            share.panel(panel,this.templateN,mId,menuName);
            this.clearTextarea();  
        },

        bindEvt : function() {
            var tthis = this,dom = $('#'+mId);
            dom.find('.back').on('tap',function(e){
                window.location.href = '#setting/whole';
            });

            dom.find('.btn-feedback').on('tap',function(){
                var obj= {};
                obj.text = dom.find('.feedback_subject').find('option :selected').val(); 
                obj.subject = dom.find('.feedback_text').find('textarea').val();
                if (obj.subject=='') {
                    alert('content is required!');
                    return;
                }
                tthis.ajaxData(obj);
            });
        },
                 
        ajaxData : function(data) {
            var tthis = this,
                dom = $('#'+mId).find('.btn');
                dom.attr('ajax',1);
                share.ajaxStartA(dom);
            var obj = {
                url : seajs.data.vars.apiAccessUrl+'feedback',
                type : 'POST',
                data : data,
                success : function(data) {
                    //console.log(71,data);
                   tthis.clearTextarea();  
                   alert(data.msg);
                    //window.location.href = '#setting/whole';
                }, 
                error : function(xhr, errorType, error) {
                    share.error('alert','http request failed!'); 
                },
                complete : function(xhr,status){
                    dom.attr('ajax',0);
                    share.ajaxEndA(dom);
                } 
            };
            $.ajax(share.ajaxControl(obj));
        },

        clearTextarea : function() {
            var dom = $('#'+mId);
            dom.find('.feedback_text').find('textarea').val('');
        }

    });

    module.exports = feedbackView;
});
